﻿using Fantasy;
using Fantasy.Async;
using Fantasy.Entitas.Interface;
using Fantasy.Network;
using Fantasy.Network.Interface;

namespace Entity.Handler.CustomRouteHandler;

public class User : Fantasy.Entitas.Entity
{
    public string Name = "User";
    public int Age = 21;

    public List<int> NumList = new List<int>();
}

/// <summary>
/// 操作数据库的测试代码
/// </summary>
public class C2G_TestMsgHandler : Message<C2G_TestMsg>
{
    protected override async FTask Run(Session session, C2G_TestMsg message)
    {
        var scene = session.Scene;
        var worldDateBase = scene.World.DateBase;

        // var user = Fantasy.Entitas.Entity.Create<User>(scene, true, false);
        // for (int i = 0; i < 10; i++)
        // {
        //     user.NumList.Add(i);
        // }
        //
        // await worldDateBase.Save(user);

        var query = await worldDateBase.Query<User>(d => true);
        User user = query[0];
        await user.DeserializeAsync(scene);

        foreach (var UPPER in user.NumList)
        {
            Log.Debug(UPPER.ToString());
        }
        
        Log.Debug("进行了数据库操作");
    }
}